package com.nutricia.common.lang;

import com.nutricia.core.ex.BizErrorCode;
import com.nutricia.core.ex.BizException;

/**
 * @author: huangsheng
 * @date: 2018/4/11
 */
public class CommonServiceExecuteTemplate implements ServiceExecuteTemplate {


    @Override
    public <T extends BaseResponse> T executeService(T result, ServiceCallBack serviceCallBack) {
        try {
            serviceCallBack.check();
            serviceCallBack.doService();
        } catch (BizException be) {
            BizErrorCode bizErrorCode = be.getErrorCodeEnum();
            result.setCode(bizErrorCode.getCode());
            result.setMessage(bizErrorCode.getDescription());
            result.setSuccess(false);
        } catch (Exception var14) {
            result.setCode(BizErrorCode.UNKNOWN_ERROR.getCode());
            result.setMessage(var14.getMessage());
            result.setSuccess(false);
        }
        return result;
    }
}
